<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page import="com.boxin.ims.modules.wechat.entity.Lottery"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<meta charset="utf-8">
<title>砸金蛋--【${lottery.name }】</title>
<link rel="stylesheet" type="text/css" href="${ctxStatic}/lottery/css/main.css" />
<style type="text/css">
.egg{width:1100px; height:400px; margin:50px auto 20px auto;}
.egg ul li{z-index:999;}
.eggList{padding-top:110px;position:relative;width:1100px;}
.eggList li{float:left;background:url(${ctxStatic}/lottery/eggs/images/egg_1.png) no-repeat bottom;width:158px;height:187px;cursor:pointer;position:relative;margin-left:35px;}
.eggList li span{position:absolute; width:30px; height:60px; left:68px; top:64px; color:#ff0; font-size:42px; font-weight:bold}
.eggList li.curr{background:url(${ctxStatic}/lottery/eggs/images/egg_2.png) no-repeat bottom;cursor:default;z-index:300;}
.eggList li.curr sup{position:absolute;background:url(${ctxStatic}/lottery/eggs/images/img-4.png) no-repeat;width:232px; height:181px;top:-36px;left:-34px;z-index:800;}
.hammer{background: url('${ctxStatic}/lottery/eggs/images/img-6.png') no-repeat scroll 0% 0% transparent;width:74px;height:87px;position:absolute; text-indent:-9999px;z-index:150;left:168px;top:50px;}


.winners {width:90px; height:200px;border-width:1px;border-style:solid; border-color:orange; font-size:14px; float: right;text-align: center;font-style: normal;color: red;}
.winners ul li{z-index:989;}
.winners li {float:right;position:relative;margin-left:1px;width: 89px;}


.resultTip{position:absolute; background:#ffc ;width:148px;padding:6px;z-index:500;top:200px; left:10px; color:#f60; text-align:center;overflow:hidden;display:none;z-index:500;}
.resultTip b{font-size:14px;line-height:24px;}
</style>
</head>

<body>

	<h1 id="lottery_title" style="color:red" align="center">本次砸金蛋奖品为:<strong>【${lottery.name }】</strong></h2>
	<h2 id="lottery_title" style="color:red" align="center">现在参与抽奖的人数为 <span id="persons">${persons } </span>人<span id="notip"><c:if test="${lotteryFlag eq '0' }">,因不足${lottery.peramount }人暂时不能进行砸金蛋抽奖活动.</c:if></span></h2>
	<div class="winners" align="center">
	<span><b>中奖名单</b></span>
	<div >
		<ul id="winer"  >
		</ul>
	</div>
	</div>
	<div class="egg" align="center">
		<ul class="eggList">
			<p class="hammer" id="hammer">锤子</p>
			<p class="resultTip" id="resultTip"><b id="result"></b></p>
			<%
				Lottery lt = (Lottery)request.getAttribute("lottery");
				int pCount = lt.getPeramount();
				for(int i=1;i<=pCount;i++){
			%>
			<li><span><%=i %></span><sup></sup></li>
				
			<%} %>
		</ul>
		
		
	</div>
	
	

<script type="text/javascript" src="${ctxStatic}/lottery/eggs/js/jquery.js"></script>
<script type="text/javascript">



var djs = setInterval("updatePersons()", 2000);

//更新人数
function updatePersons(){
	$.getJSON("${ctx}/wechat/lottery/queryLotteryQueue?userId=${lottery.user.id}",function(res){
		$("#persons").html(res.persons);
		if(res.persons >= '${lottery.peramount }'){
			$("#notip").html("");
		}
	});
}



function eggClick(obj) {
	
  var _this = obj;
  $.getJSON("${ctx}/wechat/lottery/doEggsLottery?lotteryId=${lottery.id}&userId=${lottery.user.id}",function(res){//ajax请求
    _this.unbind('click'); //解除click
    $(".hammer").css({"top":_this.position().top-55,"left":_this.position().left+185});
    $(".hammer").animate({//锤子动画
      "top":_this.position().top-25,
      "left":_this.position().left+125
      },30,function(){
        _this.addClass("curr"); //蛋碎效果
        _this.find("sup").show(); //金花四溅
        $(".hammer").hide();//隐藏锤子
        $('.resultTip').css({display:'block',top:'100px',left:_this.position().
                left+45,opacity:0})
                .animate({top: '50px',opacity:1},300,function(){//中奖结果动画
          if(res.success==1){//返回结果
            $("#result").html("恭喜手机号为【"+res.memberMobile+"】的【"+res.memberName+"】中得【"+res.lotteryName+"】奖品!");
          	$("#winer").append("<li>"+res.memberName+"</li>");
          }else{
            $("#result").html("很遗憾,您没能中奖!");
          }
        });	
      }
    );
  });
}



$(".eggList li").click(function() {
	
	
	var pCount = $("#persons").html();
	if(pCount < '${lottery.peramount }'){
		alert("参与人数不足${lottery.peramount }人,不能砸~");
		return false;
	}
	
	$(this).children("span").hide();
	eggClick($(this));
});

$(".eggList li").hover(function() {
	var posL = $(this).position().left + $(this).width();
	$("#hammer").show().css('left', posL);
})
</script>

</body>
</html>
